package com.yzt.loginmodule.login;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.yzt.zhuju.arouter.RouterAccount;
import com.yzt.zhuju.mvp.MVPActivity;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.login.GetSMSCodeRequest;
import com.yzt.loginmodule.R;

/**
 * author : bob
 * date   : 2022/12/1
 * desc   : 找回密码
 */
@Deprecated
@Route(path = RouterAccount.ACTIVITY_FIND_PASSWORD)
public class FindPasswordActivity extends MVPActivity {

    private TextView tvSure;
    private EditText etInputMobileNo;

    private TextView tvTitle, et_pwd2, et_pwd1, tv_get_code;

    @Autowired
    int type;

    @Override
    public int getLayoutId() {
        return R.layout.activity_find_password;
    }

    @Override
    public void installViews() {

        setFullScreen(true, R.color.transparent);

        tvTitle = findViewById(R.id.tv_title);
        et_pwd1 = findViewById(R.id.et_pwd1);
        et_pwd2 = findViewById(R.id.et_pwd2);
        tv_get_code = findViewById(R.id.tv_get_code);
        tv_get_code.setOnClickListener(this);
        // tvTitle.setText(type == 1?getString(R.string.set_pwd):getString(R.string.find_passwd));

        tvSure = findViewById(R.id.tv_sure);
        etInputMobileNo = findViewById(R.id.et_input_mobile_no);

        findViewById(R.id.iv_exit).setOnClickListener(this);
        tvSure.setOnClickListener(this);
        setCommitStatus();
        etInputMobileNo.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                setCommitStatus();
            }
        });
    }

    @Override
    protected void onClick(int clickId) {
        super.onClick(clickId);
        if (clickId == R.id.tv_sure) {
            getVerifyCode();
        } else if (clickId == R.id.iv_exit) {
            mActivity.finish();
        }else if (clickId == R.id.tv_get_code) {
            showToast("获取验证码");
        }
    }

    /**
     * 获取验证码
     */
    private void getVerifyCode() {
        int type = 2;

        String mobile = etInputMobileNo.getText().toString();
        GetSMSCodeRequest codeRequest = new GetSMSCodeRequest();

        codeRequest.setPhone(mobile);
        codeRequest.setSmsType(type);
        codeRequest.setType(1);
        showMProgress();
        BizLayer.getInstance().getAccountModule().getVerifyCode(codeRequest, new AresSubscriber() {
            @Override
            protected void onSuccess(Object o) {
                // RouterAccount.VerifyCodeActivity(mActivity, mobile, code, type);
            }

            @Override
            protected void onFinallyEnd() {
                super.onFinallyEnd();
                closeProgress();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_CANCELED) {
            return;
        }
        {
            setResult(RESULT_OK);
            mActivity.finish();
        }
    }


    private void setCommitStatus() {
        String mobile = etInputMobileNo.getText().toString();
        tvSure.setEnabled(mobile.length() >= 6);
    }
}
